#ifndef AUDIODECODETHREAD_H
#define AUDIODECODETHREAD_H

#include <QObject>
#include <QThread>
#include <QWaitCondition>
#include <QMutex>
#include "ffinclude.h"

class VideoPlayer;

/*
    音频解码线程
*/
class AudioDecodeThread : public QThread
{
    Q_OBJECT
public:
    explicit AudioDecodeThread(VideoPlayer *player);

    void play();
    void pause();
    void stop();

signals:
    void inited();
    void error(const QString& errMsg);

protected:
    void run();

private:
    bool openDecoder();
    void closeDecoder();
    bool decodeNextFrame( AVFrame *frame,bool* valid);
    bool enqueueFrame(AVFrame *src_frame, double pts, double duration, int64_t pos, int serial);


private:
    VideoPlayer* m_player;

    QMutex m_waitMutex;
    QWaitCondition m_waitCond;
    bool m_reqStop;
    bool m_reqPause;
    QString m_lastErrorMsg;
};

#endif // AUDIODECODETHREAD_H
